package ocm.oh.ds;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class GraphGui extends JFrame {
  /*  private ArrayList<SolutionState> solutions;
    private int width = 400; // Width of the graph
    private int height = 250; // Height of the graph
    private int padding = 25;    
    
    private int paddingLeft = 75;
    
    public static void main(String[] args) {
        ArrayList<SolutionState> solutions = new ArrayList<SolutionState>();
        
        solutions.add(new SolutionState(5, null, 70));
        solutions.add(new SolutionState(6, null, 100));
        solutions.add(new SolutionState(7, null, 250));
        solutions.add(new SolutionState(8, null, 600));
        solutions.add(new SolutionState(9, null, 400));
        solutions.add(new SolutionState(10, null, 800));
        solutions.add(new SolutionState(11, null, 900));
        solutions.add(new SolutionState(12, null, 1300));
        solutions.add(new SolutionState(13, null, 4000));
        solutions.add(new SolutionState(14, null, 6000));
        solutions.add(new SolutionState(15, null, 8000));
        
        GraphGui gui = new GraphGui("Graph", solutions);
    }
    
    
    public GraphGui(String title, ArrayList<SolutionState> solutions) {
        // Let's sort the solutions by the K value
        this.solutions = solutions;
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // This should get the solutions-arraylist sorted by K ascending
        Collections.sort(this.solutions, new IntComparable());      
        setTitle(title);
        add(new Graph());
        setSize(width+50,height+50);
        setVisible(true);
    }              
    
    private class IntComparable  implements Comparator<SolutionState>{        
        @Override
        public int compare(SolutionState s1, SolutionState s2) {
            float o2 = s1.getK();
            float o1 = s2.getK();
            return (o1>o2 ? -1 : (o1==o2 ? 0 : 1));
        }
    }
    
    private class Graph extends JPanel {
        
        @Override
        public void paintComponent(Graphics g) {
            setBackground(Color.WHITE);            
            int lowestK = solutions.get(0).getK();
            int highestK = solutions.get(solutions.size()-1).getK();
            
            long highestTime = 0;
            for(int i=0; i < solutions.size(); i++) {
                if(solutions.get(i).getRunTimeInMs() > highestTime) highestTime = solutions.get(i).getRunTimeInMs();
            }
            
            long lowestTime = highestTime; // Initializing it with the highest value found..
            
            for(int i=0; i < solutions.size(); i++)  {
                if(solutions.get(i).getRunTimeInMs() < lowestTime) lowestTime = solutions.get(i).getRunTimeInMs();
            }
            
            // Start by drawing the Y and X axis ( padding = 50 px )

            g.drawLine(paddingLeft, 0, paddingLeft, height); // Top-to-bottom
            g.drawLine(paddingLeft, height, width, height);   // Left-to-right          
            
            // How many intervals? Maximum 10. Starting at 0            
            int maxIntervalsY = 10;
            
            for(int i=0; i < solutions.size(); i++) {
                SolutionState s = solutions.get(i);
                // Draw the text for the K value
                
            }
                        
            
            
                         
            // Let's create a graph that is 400px in width..
            // Leaving 400/ diff(lowestK,highestK) for each k
            
        }
        
        
    }
    
    private double getY(long maxRunTimeInMs, long runTimeInMs) {
        return (runTimeInMs/maxRunTimeInMs) * (double)height;
    } */
}
